<?php
/**
 * @author Terence Yan <terence.yan@me.com>
 * Check Authetnication of submitted user and hash.
 * @param $username accountname
 * @param $pass password (hashed)
 * @return bool true false success status.
 */

function checkAuthentication($username, $pass)
{
    $output = false;
    $host = 'localhost';
    $sqluser = 'root';
    $sqlpass = '';
    $sqlDB = 'paradigmShift_DEV';

    $context = mysqli_connect($host, $sqluser, $sqlpass, $sqlDB);

    if (!mysqli_connect_errno()) {
        $query = "CALL GetAuthValue('$username')";

        if ($result = mysqli_query($context, $query)) {

            if ($obj = mysqli_fetch_object($result)) {

                if ($obj->password == $pass) {
                    $output = true;
                }

            }
            $result->close();
        }
        $context->close();
    } else {
        $output = mysqli_connect_errno();
    }

    return $output;
}

?>
